From 93f98c07cab07f4c89ebd392be5593901a579921 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Tue, 27 Nov 2018 18:48:17 -0700 Subject: [PATCH] obsolete DEBUG_MEM (#279) --- Makefile.in | 9 +---- cet_util.cc | 3 -- csv_util.cc | 2 +- csv_util.h | 10 ------ defs.h | 45 ----------------------- gbfile.cc | 4 --- gbfile.h | 3 -- main.cc | 12 ------- mkshort.cc | 18 +++------- tools/cleardebug | 5 --- tools/memdebug | 74 -------------------------------------- util.cc | 93 ++---------------------------------------------- vecs.cc | 6 +--- 13 files changed, 11 insertions(+), 273 deletions(-) delete mode 100755 tools/cleardebug delete mode 100755 tools/memdebug diff --git a/Makefile.in b/Makefile.in index 448d0ea94..d4dbfcf47 100644 --- a/Makefile.in +++ b/Makefile.in @@ -56,7 +56,6 @@ LRELEASE=@LRELEASE@ # #OPTIMIZATION=-O $(EXTRA_OPTIMIZATION) #DEBUGGING=-g $(EXTRA_DEBUGGING) -# add -DDEBUG_MEM to turn on memory allocation logging GBCFLAGS=$(EXTRA_CFLAGS) $(DEBUGGING) $(BUILD_CPP) @ZLIB_CPP@ @QT_INC_OPT@$(QT_INC) \ $(OPTIMIZATION) -DHAVE_CONFIG_H -DNEW_STRINGS LDFLAGS=$(EXTRA_LDFLAGS) @LDFLAGS@ @@ -143,7 +142,7 @@ WEB=@DOCDIR@ # Declaring a target PHONY whose names matches a subdirectory can be # particularly important, e.g. gui. .PHONY: all clean tag more-clean check torture \ -install install-debug leaktest \ +install install-debug \ dep doc \ release-sourcecheck release-tarball release-rpm \ cross-configure \ @@ -224,12 +223,6 @@ install-debug: # Nerdy release stuff that needs to work only on Linux. -leaktest: - make EXTRA_CFLAGS=-DDEBUG_MEM - tools/cleardebug - ./testo - tools/memdebug | grep -v '^command line:' - dep: make clean && make -j8 EXTRA_CFLAGS="-isystem /sw/include @QT_SYSINC_OPT@ $(QT_INC) -MMD" && cat $(sort $(DEPFILES)) > /tmp/dep && rm $(DEPFILES) echo 'internal_styles.cc: mkstyle.sh $$(srcdir)/style/*.style' >> /tmp/dep diff --git a/cet_util.cc b/cet_util.cc index c6be77ef8..758dc154f 100644 --- a/cet_util.cc +++ b/cet_util.cc @@ -94,9 +94,6 @@ cet_register_cs(cet_cs_vec_t* vec) vec->next = cet_cs_vec_root; cet_cs_vec_root = vec; cet_cs_vec_ct++; -#ifdef DEBUG_MEM - cet_check_cs(vec); -#endif } } diff --git a/csv_util.cc b/csv_util.cc index 9247ba78d..31129cb42 100644 --- a/csv_util.cc +++ b/csv_util.cc @@ -194,7 +194,7 @@ char* csv_stringtrim(const char* string, const char* enclosure, int strip_max) { static const char* p1 = nullptr; - char* tmp = xxstrdup(string,file,line); + char* tmp = xstrdup(string); size_t elen; int stripped = 0; diff --git a/csv_util.h b/csv_util.h index 25925194f..214c3e142 100644 --- a/csv_util.h +++ b/csv_util.h @@ -26,12 +26,7 @@ class QTextStream; /* function prototypes */ char* -#ifndef DEBUG_MEM csv_stringtrim(const char* string, const char* enclosure, int strip_max); -#else -CSV_STRINGTRIM(const char* string, const char* enclosure, int strip_max, DEBUG_PARAMS); -#define csv_stringtrim( s, e,m ) CSV_STRINGTRIM( s, e, m, __FILE__, __LINE__) -#endif QString csv_stringtrim(const QString& source, const QString& enclosure); char* @@ -45,12 +40,7 @@ human_to_dec(const QString& instr, double* outlat, double* outlon, int which) { } char* -#ifndef DEBUG_MEM csv_stringclean(const char* string, const char* chararray); -#else -CSV_STRINGCLEAN(const char* string, const char* chararray,DEBUG_PARAMS); -#define csv_stringclean(s,c) CSV_STRINGCLEAN(s,c,__FILE__,__LINE__) -#endif QString csv_stringclean(const QString& string, const QString& chararray); void diff --git a/defs.h b/defs.h index 4ea3ac1b9..b4aa31267 100644 --- a/defs.h +++ b/defs.h @@ -815,13 +815,7 @@ typedef void (*ff_exit)(void); typedef void (*ff_writeposn)(Waypoint*); typedef Waypoint* (*ff_readposn)(posn_status*); -#ifndef DEBUG_MEM char* get_option(const char* iarglist, const char* argname); -#else -#define DEBUG_PARAMS const char *file, const int line -char* GET_OPTION(const char* iarglist, const char* argname, DEBUG_PARAMS); -#define get_option(iarglist, argname) GET_OPTION(iarglist, argname, __FILE__, __LINE__) -#endif void xcsv_setup_internal_style(const char* style_buf); void xcsv_read_internal_style(const char* style_buf); @@ -851,16 +845,9 @@ typedef struct { } mkshort_handle_imp; typedef mkshort_handle_imp* short_handle; -#ifndef DEBUG_MEM char* mkshort(short_handle, const char*); QString mkshort(short_handle, const QString&); short_handle mkshort_new_handle(void); -#else -char* MKSHORT(short_handle, const char*, DEBUG_PARAMS); -short_handle MKSHORT_NEW_HANDLE(DEBUG_PARAMS); -#define mkshort( a, b) MKSHORT(a,b,__FILE__, __LINE__) -#define mkshort_new_handle() MKSHORT_NEW_HANDLE(__FILE__,__LINE__) -#endif QString mkshort_from_wpt(short_handle h, const Waypoint* wpt); void mkshort_del_handle(short_handle* h); void setshort_length(short_handle, int n); @@ -1002,7 +989,6 @@ void disp_formats(int version); const char* name_option(long type); void printposn(const double c, int is_lat); -#ifndef DEBUG_MEM void* xcalloc(size_t nmemb, size_t size); void* xmalloc(size_t size); void* xrealloc(void* p, size_t s); @@ -1010,38 +996,7 @@ void xfree(const void* mem); char* xstrdup(const QString& s); char* xstrndup(const char* str, size_t sz); char* xstrappend(char* src, const char* newd); -#define xxcalloc(nmemb, size, file, line) xcalloc(nmemb, size) -#define xxmalloc(size, file, line) xmalloc(size) -#define xxrealloc(p, s, file, line) xrealloc(p,s) -#define xxfree(mem, file, line) xfree(mem) -#define xxstrdup(s, file, line) xstrdup(s) char* xstrdup(const char* s); -#define xxstrappend(src, addon, file, line) xstrappend(src, addon) -#else /* DEBUG_MEM */ -void* XCALLOC(size_t nmemb, size_t size, DEBUG_PARAMS); -void* XMALLOC(size_t size, DEBUG_PARAMS); -void* XREALLOC(void* p, size_t s, DEBUG_PARAMS); -void XFREE(void* mem, DEBUG_PARAMS); -char* XSTRDUP(const char* s, DEBUG_PARAMS); -char* XSTRNDUP(const char* src, size_t size, DEBUG_PARAMS); -char* XSTRAPPEND(char* src, const char* addon, DEBUG_PARAMS); -void debug_mem_open(); -void debug_mem_output(char* format, ...); -void debug_mem_close(); -#define xcalloc(nmemb, size) XCALLOC(nmemb, size, __FILE__, __LINE__) -#define xmalloc(size) XMALLOC(size, __FILE__, __LINE__) -#define xrealloc(p, s) XREALLOC(p,s,__FILE__,__LINE__) -#define xfree(mem) XFREE(mem, __FILE__, __LINE__) -#define xstrdup(s) XSTRDUP(s, __FILE__, __LINE__) -#define xstrndup(s, z) XSTRNDUP(s, z, __FILE__, __LINE__) -#define xstrappend(src,addon) XSTRAPPEND(src, addon, __FILE__, __LINE__) -#define xxcalloc XCALLOC -#define xxmalloc XMALLOC -#define xxrealloc XREALLOC -#define xxfree XFREE -#define xxstrdup XSTRDUP -#define xxstrappend XSTRAPPEND -#endif /* DEBUG_MEM */ FILE* xfopen(const char* fname, const char* type, const char* errtxt); diff --git a/gbfile.cc b/gbfile.cc index bc5f36abf..e4561cd90 100644 --- a/gbfile.cc +++ b/gbfile.cc @@ -581,11 +581,7 @@ gbfopen(const QString& filename, const char* mode, const char* module) file->fileopen(file, mode); -#ifdef DEBUG_MEM - file->buffsz = 1; -#else file->buffsz = 256; -#endif file->buff = (char*) xmalloc(file->buffsz); return file; diff --git a/gbfile.h b/gbfile.h index 8979ee5ef..10a0cad78 100644 --- a/gbfile.h +++ b/gbfile.h @@ -46,9 +46,6 @@ typedef gbsize_t (*gbfwrite_cb)(const void* buf, const gbsize_t size, const gbsi typedef int (*gbfungetc_cb)(const int c, gbfile* self); typedef struct gbfile_s { -#ifdef DEBUG_MEM - void* dummy; /* ZERO pointer for stdio oop's */ -#endif union { FILE* std; unsigned char* mem; diff --git a/main.cc b/main.cc index 0c56985fa..575659be3 100644 --- a/main.cc +++ b/main.cc @@ -278,15 +278,6 @@ main(int argc, char* argv[]) gpsbabel_now = time(nullptr); /* gpsbabel startup-time */ gpsbabel_time = current_time().toTime_t(); /* same like gpsbabel_now, but freezed to zero during testo */ -#ifdef DEBUG_MEM - debug_mem_open(); - debug_mem_output("command line: "); - for (int i = 1; i < qargs.size(); i++) { - debug_mem_output("%s ", qPrintable(qargs.at(i))); - } - debug_mem_output("\n"); -#endif - if (gpsbabel_time != 0) { /* within testo ? */ global_opts.inifile = inifile_init(QString(), MYNAME); } @@ -735,9 +726,6 @@ main(int argc, char* argv[]) exit_filter_vecs(); inifile_done(global_opts.inifile); -#ifdef DEBUG_MEM - debug_mem_close(); -#endif exit(0); } diff --git a/mkshort.cc b/mkshort.cc index 99f0f1ab7..86a2a061d 100644 --- a/mkshort.cc +++ b/mkshort.cc @@ -81,13 +81,9 @@ unsigned int hash_string(const char* key) } short_handle -#ifdef DEBUG_MEM -MKSHORT_NEW_HANDLE(DEBUG_PARAMS) -#else mkshort_new_handle() -#endif { - mkshort_handle_imp* h = (mkshort_handle_imp*) xxcalloc(sizeof *h, 1, file, line); + mkshort_handle_imp* h = (mkshort_handle_imp*) xcalloc(sizeof *h, 1); for (int i = 0; i < PRIME; i++) { QUEUE_INIT(&h->namelist[i]); @@ -370,11 +366,7 @@ setshort_is_utf8(short_handle h, const int is_utf8) } char* -#ifdef DEBUG_MEM -MKSHORT(short_handle h, const char* istring, DEBUG_PARAMS) -#else mkshort(short_handle h, const char* istring) -#endif { char* ostring; char* tstring; @@ -385,7 +377,7 @@ mkshort(short_handle h, const char* istring) if (hdl->is_utf8) { ostring = cet_utf8_strdup(istring); /* clean UTF-8 string */ } else { - ostring = xxstrdup(istring, file, line); + ostring = xstrdup(istring); } /* @@ -406,7 +398,7 @@ mkshort(short_handle h, const char* istring) if ((strlen(ostring) > hdl->target_len + 4) && (strncmp(ostring, "The ", 4) == 0 || strncmp(ostring, "the ", 4) == 0)) { - char* nstring = xxstrdup(ostring + 4, file, line); + char* nstring = xstrdup(ostring + 4); xfree(ostring); ostring = nstring; } @@ -424,7 +416,7 @@ mkshort(short_handle h, const char* istring) /* * Eliminate Whitespace */ - tstring = xxstrdup(ostring, file, line); + tstring = xstrdup(ostring); l = strlen(tstring); cp = ostring; for (i=0; i[0], $arena{$addr}->[1], $file, $line]; - delete $arena{$addr}; - } - else { - if ($freed{$addr}) { - ($afile,$aline,$ffile,$fline) = @{$freed{$addr}}; - print( "double free $addr at $file $line\n allocated at $afile $aline\n last freed at $ffile $fline\n" ); - } - else { - print( "freeing unallocated $addr at $file $line\n" ); - } - } -} - -sub unfreed { - for $addr (keys %arena) { - ($file,$line)=@{$arena{$addr}}; - print( "unfreed $addr allocated at $file $line\n" ); - } - undef %arena; - undef %freed; -} - -open(FILE, ") { - chomp; - @args = split(', ',$_); - if ($args[0] eq 'malloc') { - &alloc($args[1], $args[3], $args[4]); - } - if ($args[0] eq 'calloc') { - &alloc($args[1], $args[4], $args[5]); - } - if ($args[0] eq 'strdup') { - &alloc($args[1], $args[3], $args[4]); - } - if ($args[0] eq 'realloc') { - &free($args[2], $args[4], $args[5]); - &alloc($args[1], $args[4], $args[5]); - } - if ($args[0] eq 'free') { - &free($args[1], $args[2], $args[3]); - } - if ($args[0] =~ m/^command/) { - &unfreed; - print "$args[0]\n"; - } -} -&unfreed; -close(FILE); diff --git a/util.cc b/util.cc index ab578925c..78986e434 100644 --- a/util.cc +++ b/util.cc @@ -45,51 +45,11 @@ #endif #endif -#ifdef DEBUG_MEM -#define DEBUG_FILENAME "/tmp/gpsbabel.debug" - -static FILE* debug_mem_file = NULL; -void -debug_mem_open() -{ - debug_mem_file = xfopen(DEBUG_FILENAME, "a", "debug"); -} - -void -debug_mem_output(char* format, ...) -{ - va_list args; - va_start(args, format); - if (debug_mem_file) { - vfprintf(debug_mem_file, format, args); - fflush(debug_mem_file); - } - va_end(args); -} - -void -debug_mem_close() -{ - if (debug_mem_file) { - fclose(debug_mem_file); - } - debug_mem_file = NULL; -} -#endif - void* -#ifdef DEBUG_MEM -XMALLOC(size_t size, DEBUG_PARAMS) -#else xmalloc(size_t size) -#endif { void* obj = malloc(size); -#ifdef DEBUG_MEM - debug_mem_output("malloc, %x, %d, %s, %d\n", - obj, size, file, line); -#endif if (!obj) { fatal("gpsbabel: Unable to allocate %ld bytes of memory.\n", (unsigned long) size); } @@ -98,17 +58,9 @@ xmalloc(size_t size) } void* -#ifdef DEBUG_MEM -XCALLOC(size_t nmemb, size_t size, DEBUG_PARAMS) -#else xcalloc(size_t nmemb, size_t size) -#endif { void* obj = calloc(nmemb, size); -#ifdef DEBUG_MEM - debug_mem_output("calloc, %x, %d, %d, %s, %d\n", - obj, nmemb, size, file, line); -#endif if (!obj) { fatal("gpsbabel: Unable to allocate %ld units of %ld bytes of memory.\n", (unsigned long) nmemb, (unsigned long) size); @@ -118,31 +70,15 @@ xcalloc(size_t nmemb, size_t size) } void -#ifdef DEBUG_MEM -XFREE(const void* mem, DEBUG_PARAMS) -#else xfree(const void* mem) -#endif { free(const_cast(mem)); -#ifdef DEBUG_MEM - debug_mem_output("free, %x, %s, %d\n", - mem, file, line); -#endif } char* -#ifdef DEBUG_MEM -XSTRDUP(const char* s, DEBUG_PARAMS) -#else xstrdup(const char* s) -#endif { char* o = s ? strdup(s) : strdup(""); -#ifdef DEBUG_MEM - debug_mem_output("strdup, %x, %x, %s, %d\n", - o, s, file, line); -#endif if (!o) { fatal("gpsbabel: Unable to allocate %ld bytes of memory.\n", (unsigned long) strlen(s)); @@ -160,11 +96,7 @@ char* xstrdup(const QString& s) * Duplicate at most sz bytes in str. */ char* -#ifdef DEBUG_MEM -XSTRNDUP(const char* str, size_t sz, DEBUG_PARAMS) -#else xstrndup(const char* str, size_t sz) -#endif { size_t newlen = 0; const char* cin = str; @@ -182,20 +114,9 @@ xstrndup(const char* str, size_t sz) } void* -#ifdef DEBUG_MEM -XREALLOC(void* p, size_t s, DEBUG_PARAMS) -#else xrealloc(void* p, size_t s) -#endif { char* o = (char*) realloc(p, s); -#ifdef DEBUG_MEM - if (p != NULL) { - debug_mem_output("realloc, %x, %x, %x, %s, %d\n", o, p, s, file, line); - } else { - debug_mem_output("malloc, %x, %d, %s, %d\n", o, s, file, line); - } -#endif if (!o) { fatal("gpsbabel: Unable to realloc %ld bytes of memory.\n", (unsigned long) s); @@ -208,21 +129,17 @@ xrealloc(void* p, size_t s) * For an allocated string, realloc it and append 's' */ char* -#ifdef DEBUG_MEM -XSTRAPPEND(char* src, const char* newd, DEBUG_PARAMS) -#else xstrappend(char* src, const char* newd) -#endif { if (!src) { - return xxstrdup(newd, file, line); + return xstrdup(newd); } if (!newd) { - return xxstrdup(src, file, line); + return xstrdup(src); } size_t newsz = strlen(src) + strlen(newd) + 1; - src = (char*) xxrealloc(src, newsz, file, line); + src = (char*) xrealloc(src, newsz); strcat(src, newd); return src; @@ -325,11 +242,7 @@ xvasprintf(char** strp, const char* fmt, va_list ap) { /* From http://perfec.to/vsnprintf/pasprintf.c */ /* size of first buffer malloc; start small to exercise grow routines */ -#ifdef DEBUG_MEM -# define FIRSTSIZE 64 -#else # define FIRSTSIZE 1 -#endif char* buf = nullptr; char* newbuf; size_t nextsize = 0; diff --git a/vecs.cc b/vecs.cc index ad18c2780..7267cc80b 100644 --- a/vecs.cc +++ b/vecs.cc @@ -1387,11 +1387,7 @@ find_vec(const char* vecname, const char** opts) * Modelled approximately after getenv. */ char* -#ifdef DEBUG_MEM -GET_OPTION(const char* iarglist, const char* argname, DEBUG_PARAMS) -#else get_option(const char* iarglist, const char* argname) -#endif { const size_t arglen = strlen(argname); char* rval = nullptr; @@ -1425,7 +1421,7 @@ get_option(const char* iarglist, const char* argname) * this data. */ if (rval) { - rval = xxstrdup(rval,file, line); + rval = xstrdup(rval); } xfree(arglist); return rval; -- 2.30.2